<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item :label="$t('业务时间')">
              <j-date :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }" valueFormat="YYYY-MM-DD HH:mm:ss" dateFormat="YYYY-MM-DD HH:mm:ss" :placeholder="$t('请选择开始时间')" class="query-group-cust" v-model="queryParam.createTime_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }" valueFormat="YYYY-MM-DD HH:mm:ss" dateFormat="YYYY-MM-DD HH:mm:ss" :placeholder="$t('请选择结束时间')" class="query-group-cust" v-model="queryParam.createTime_end"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('订单号')">
              <a-input :placeholder="$t('请输入订单号')" v-model="queryParam.orderId"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('商品')">
                <j-search-select-tag :placeholder="$t('请选择商品')" v-model="queryParam.goodsId" dict="bis_goods_infor,name,id"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('操作员')">
                <a-input :placeholder="$t('请输入操作员')" v-model="queryParam.createBy"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{$t('查询')}}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{$t('重置')}}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" :loading="exloading" @click="handleExportXls($t('其他入库明细'))" v-has="'BisGoodsInstockDetailsController:export'">{{$t('导出')}}</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">{{$t('无图片')}}</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">{{$t('无文件')}}</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            {{$t('下载')}}
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">{{$t('详情')}}</a>
        </span>
        <template slot="footer">
          <div style="font-weight: bold">
            <span>{{$t('数量')}}：{{ totalInfo.number }}</span>
            <span style="margin-left:16px;">{{$t('总金额')}}：{{ totalInfo.totalAmount }}</span>
          </div>
        </template>
      </a-table>
    </div>
  </a-card>
</template>

<script>
  import moment from 'moment'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'

  export default {
    name: 'BisGoodsOtherInstockDetails',
    mixins:[JeecgListMixin, mixinDevice],
    components: {},
    data () {
      return {
        description: '其他入库明细',
        moment,
        // 表头
        columns: [
          {
            title:this.$t('订单号'),
            align:"center",
            dataIndex: 'orderId'
          },
          {
            title:this.$t('业务时间'),
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title:this.$t('商品编码'),
            align:"center",
            dataIndex: 'goodsCode'
          },
          {
            title:this.$t('商品名称'),
            align:"center",
            dataIndex: 'goodsId_dictText'
          },
          {
            title:this.$t('成本'),
            align:"right",
            dataIndex: 'unitPrice',
            customRender: (text, r) => {
              return text.toFixed(2);
            }
          },
          {
            title:this.$t('入库数量'),
            align:"right",
            dataIndex: 'number',
            customRender: (text, r) => {
              return text.toFixed(0);
            }
          },
          {
            title:this.$t('总金额'),
            align:"right",
            dataIndex: 'totalAmount',
            customRender: (text, r) => {
              return text.toFixed(2);
            }
          },
          {
            title:this.$t('备注'),
            align:"center",
            dataIndex: 'comement'
          },
          {
            title:this.$t('操作员'),
            align:"center",
            dataIndex: 'createBy'
          }
        ],
        url: {
          list: "/goods/bisGoodsInstockDetails/list",
          delete: "/goods/bisGoodsInstockDetails/delete",
          deleteBatch: "/goods/bisGoodsInstockDetails/deleteBatch",
          exportXlsUrl: "/goods/bisGoodsInstockDetails/exportXls",
          importExcelUrl: "goods/bisGoodsInstockDetails/importExcel",
        },
        dictOptions:{},
        superFieldList:[],
        queryParam:{
          inType:'2'
        },
        totalCallback: this.totalCallbacks,
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      totalCallbacks(totalInfo){
        this.totalInfo=totalInfo
      },
      searchReset(){
        this.queryParam={
          inType:'2'
        }
        this.searchQuery()
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'sel_search',value:'goodsId',text:this.$t('商品ID'),dictTable:"bis_goods_infor", dictText:'name', dictCode:'id'})
        fieldList.push({type:'int',value:'number',text:this.$t('入库数量'),dictCode:''})
        fieldList.push({type:'BigDecimal',value:'unitPrice',text:this.$t('单价'),dictCode:''})
        fieldList.push({type:'BigDecimal',value:'totalAmount',text:this.$t('总金额'),dictCode:''})
        fieldList.push({type:'string',value:'comement',text:this.$t('备注'),dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>